package dataStructure.Test053最大子数组和;

class Solution {
    public int maxSubArray(int[] nums) {
        int Sum = 0;
        int maxSum = nums[0];
        for (int num : nums) {
            if (Sum >= 0) {
                Sum += num;
            } else {
                Sum = num;
            }
           if (maxSum<Sum){
               maxSum=Sum;
           }
        }
        return maxSum;
    }
}